/*****************************************************************************
*        描述 :
*             文件描述
*        CLR版本:            3.5
*        创建者 :            蒋 光
*        个人域名:           jiangguang.net.cn
*        命名空间名称:       ECP.Utilities
*        文件名:             BaseCheckInput.cs
*        创建系统时间:       2012/11/2 19:07:07
*        创建年份:           2012
*
/*****************************************************************************/

namespace ECP.Utilities
{
    using System.IO;
    using System.Text.RegularExpressions;
    using System.Windows.Forms;
    using DevExpress.XtraEditors;

    public class BaseCheckInput
    {
        public static bool CheckEmail(string email)
        {
            bool flag = true;
            if (email.Trim().Length == 0)
            {
                return true;
            }
            Regex regex = new Regex(@"[\w-]+@([\w-]+\.)+[\w-]+");
            if (!regex.IsMatch(email))
            {
                flag = false;
            }
            return flag;
        }

        public static bool CheckEmail(Control Control, string message)
        {
            bool flag = true;
            if (!CheckEmail(Control.Text))
            {
               XtraMessageBox.Show(message, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                Control.Focus();
                flag = false;
            }
            return flag;
        }

        public static bool CheckEmpty(Control Control, string message)
        {
            bool flag = true;
            if (Control.Text.Length == 0)
            {
                flag = false;
                Control.Focus();
                Control.Select();
                if (message.Length > 0)
                {
                   XtraMessageBox.Show(message, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
            }
            return flag;
        }

        public static bool CheckFileName(string fileName)
        {
            bool flag = true;
            if (fileName.Trim().Length == 0)
            {
                return false;
            }
            if (fileName.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
            {
                flag = false;
            }
            return flag;
        }

        public static bool CheckFileName(Control Control, string message)
        {
            bool flag = true;
            if (!CheckFileName(Control.Text))
            {
               XtraMessageBox.Show(message, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                Control.Focus();
                flag = false;
            }
            return flag;
        }

        public static bool CheckFolderName(string folderName)
        {
            bool flag = true;
            if (folderName.Trim().Length == 0)
            {
                return false;
            }
            return (((folderName.IndexOfAny(Path.GetInvalidPathChars()) < 0) && (folderName.IndexOfAny(Path.GetInvalidFileNameChars()) < 0)) && flag);
        }

        public static bool CheckFolderName(Control Control, string message)
        {
            bool flag = true;
            if (!CheckFolderName(Control.Text))
            {
               XtraMessageBox.Show(message, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                Control.Focus();
                flag = false;
            }
            return flag;
        }
    }
}